/*
 * @Description:
 * @Author: zheng yiliang
 * @Date: 2021-03-27 23:16:29
 * @LastEditTime: 2021-03-28 12:00:57
 * @LastEditors: zheng yiliang
 */


const NodeRSA = require('node-rsa')
// const fs = require('fs')

// Generate new 512bit-length key 
var key = new NodeRSA({ b: 1024 })
key.setOptions({ encryptionScheme: 'pkcs1' })

// exports.PUBLICK_KEY = key.exportKey("pkcs8-public-pem")

var privatePem = key.exportKey('pkcs1-private-pem')
var publicDer = key.exportKey('pkcs8-public-der')
var publicDerStr = publicDer.toString('base64')

exports.PUBLIC_KEY = publicDerStr // 公钥

exports.decrypted = (val) => { // 返回解密后的数据
  key.importKey(privatePem); //导入私钥
  return key.decrypt(val, 'utf8');  //解密
}



